package com.cxy.datawarehouse.response;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

/**
 * 通用返回对象
 *
 * @author admin
 */
@ApiModel
public class Result<T> implements Serializable {

    @ApiModelProperty(value = "响应码", example = "0")
    private int code;


    @ApiModelProperty(value = "响应消息", example = "成功")
    private String message;


    @ApiModelProperty(value = "响应的数据")
    private T data;

    public Result() {

    }

    public Result(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public Result(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> Result<T> ok() {
        return new Result<T>(ResultStatus.OK.getCode(), ResultStatus.OK.getMessage(), null);
    }

    public static <T> Result<T> ok(T data) {
        return new Result<>(ResultStatus.OK.getCode(), ResultStatus.OK.getMessage(), data);
    }

    public static <T> Result<T> error(IResultStatus status, String message) {
        return new Result<>(status.getCode(), message);
    }

    public static <T> Result<T> error(String message) {
        return new Result<T>(-1, message);
    }

    public static <T> Result<T> error(Integer code, T data) {
        return new Result<T>(code, "error", data);
    }

    public static <T> Result<T> error(Integer code, String msg) {
        return new Result<T>(code, msg, null);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
